<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>组合对话框</title>
        <#include "/pubHeadStyle.html">
    </head>
    <body>
        <ul id="treeClass" class="ztree ccpui-listZtree" style="top:0;bottom:58px;"></ul>
        <div style="position: absolute;bottom: 10px;left: 33%;">
            <a class="layui-btn determine">
                <span>确定</span>
            </a>
            <a class="layui-btn reset">
                <span>重置</span>
            </a>
            <a class="layui-btn layui-btn-danger cancel">
                <span>取消</span>
            </a>
        </div>
        <script>
            layui.config({
                base: serverPath.formPath + staticPath.formPath //静态资源所在路径
            }).extend({
                index: 'index' //主入口模块
            }).use(['index', 'table', 'layer', 'jquery', 'form', 'tree', 'commons', 'common', 'totalFilter', 'setter'], function () {
                var table = layui.table, layer = layui.layer, setter = layui.setter, commons = layui.commons,
                    common = layui.common;
                $(".cancel").on('click', function () {
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                });
                $(".reset").on('click', function () {
                    window.location.reload();
                });
                resZtrees();

                function resZtrees() {
                    $.ajax({
                        url: serverPath.formPath + setter.sysLinkPath + "globalType/list",
                        type: "post",
                        dataType: 'json',
                        data: {"catKey": "FORM_TYPE", "hasRoot": 1},
                        success: function (data) {
                            var zNodes = data.data;
                            var setting = {
                                view: {
                                    showLine: false,
                                    nameIsHTML: true, //允许name支持html
                                    selectedMulti: false
                                },
                                edit: {
                                    enable: false,
                                    editNameSelectAll: false
                                },
                                data: {
                                    simpleData: {
                                        enable: true,
                                        idKey: "typeId",
                                        pIdKey: "parentId"

                                    },
                                    key: {
                                        name: "typeName"
                                    }
                                },

                                callback: {
                                    onClick: onClickType
                                }
                            };
                            $.fn.zTree.init($('#treeClass'), setting, zNodes);
                            component.fuzzySearch('treeClass', '.classZtreeValue', null, true); //初始化模糊搜索方法
                        }
                    });
                }

                var categoryId = "";
                var categoryName = "";

                function onClickType(event, treeId, treeNode) {
                    categoryId = treeNode.typeId;
                    categoryName = treeNode.typeName;
                    $(".determine").on('click', function () {
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                        parent.layer.alert(JSON.stringify(treeNode), {title: '提示', area: ['360px', '300px']});
                    });
                    var url = serverPath.formPath + setter.formLinkPath + 'formDef/list?categoryId=' + categoryId;
                    if (null == treeNode.parentId) {
                        url = serverPath.formPath + setter.formLinkPath + 'formDef/list'
                    }
                }
            })
        </script>
    </body>
</html>